package com.cy.pj.sys.service.impl;

import com.cy.pj.common.exeption.serviceException;
import com.cy.pj.sys.dao.SysNoticeDao;
import com.cy.pj.sys.pojo.SysNotice;
import com.cy.pj.sys.service.SysNoticeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @DATE:2021/3/9 20:49
 * @Author: LuckyH
 */

@Service
public class SysNoticeServiceImpl implements SysNoticeService {

    // 还有一种值注入的方式：通过构造器给值赋值
    //@Autowired
    private SysNoticeDao sysNoticeDao;
    public SysNoticeServiceImpl(SysNoticeDao sysNoticeDao) {
        this.sysNoticeDao = sysNoticeDao;
    }

    // 通过工厂创建日志对象
    private static final Logger log = LoggerFactory.getLogger(SysNoticeServiceImpl.class);


    @Override
    public int saveNotice(SysNotice notice) {
        //int rows = SysNoticeDao.insertNotice(notice);
        int rows = sysNoticeDao.insertNotice(notice);
        return rows;
    }

    @Override
    public List<SysNotice> findNotices(SysNotice notice) {
        long t1 = System.currentTimeMillis();
        log.info("method start {}",t1);
        List<SysNotice> sysNotices = sysNoticeDao.selectNotices(notice);
        long t2 = System.currentTimeMillis();
        log.info("method end {}",t2);
        return sysNotices;
    }

    @Override
    public int deleteById(Long... ids) {
        int rows = sysNoticeDao.deleteById(ids);
        if (rows==0){
           // throw new RuntimeException("记录可能已经不存在了！");
            throw new serviceException("记录可能已经不存在了！");
        }
        return rows;
    }

    @Override
    public SysNotice findById(Long id) {
        SysNotice sysNotice = sysNoticeDao.selectById(id);
        return sysNotice;
    }

    @Override
    public int updateNotice(SysNotice notice) {
        int rows = sysNoticeDao.updateNotice(notice);
        return rows;
    }
}
